<template>
  <div class="rights">
    <!-- 面包屑导航区 -->
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片试图区 -->
    <el-card class="box-card">
      <el-table :data="rightsList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="权限名称" prop="powername"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="权限等级" prop="grade">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.grade === 1">一级</el-tag>
            <el-tag type="success" v-else-if="scope.row.grade === 2">二级</el-tag>
            <el-tag type="warning" v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
export default {
  name: "rights",
  created() {
    // 获取所有的权限
    this.getrightsList();
  },
  data() {
    return {
      // 权限列表
      rightsList: []
    };
  },
  methods: {
    // 获取所有的权限
    async getrightsList() {
      let anonymousLogin = await this.$login();
      // 若匿名登录失败就直接停止了
      if (!anonymousLogin) return;
      let res = await this.$cloudbase.callFunction({
        name: "power",
        data: {
          methods: "getrightsList"
        }
      });
      this.rightsList = res.result.data;
    }
  }
};
</script>
<style lang="less" scoped>
</style>